package org.itsky.study.test1;

/**
 * @Author sky
 * @Site cmtianxie163.com 2020/4/10 15:50
 */

import java.util.Comparator;

/**
 * 方法引用
 */

public class LambdaTest3 {

    public static void main(String[] args) {
        //匿名内部类写法
        Comparator<Integer> com1 = new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return Integer.compare(o1,o2);
            }
        };
        int compare1 = com1.compare(10, 20);
        System.out.println(compare1);
        System.out.println("*****************************");

        //lambda 写法
        Comparator<Integer> com2 = (o1,o2) -> Integer.compare(o1,o2);
        int compare2 = com2.compare(10, 20);
        System.out.println(compare2);
        System.out.println("*****************************");

        //方法引用
        Comparator<Integer> com3 = Integer::compare;
        int compare3 = com3.compare(20, 10);
        System.out.println(compare3);
    }

}
